package com.salesmonitoring.accounts.view;

import javax.swing.table.AbstractTableModel;

@SuppressWarnings("serial")
class MyTableModel extends AbstractTableModel {
	
	String titles[] = new String[] { "Username", "Name", "Warehouse", "Role" };

	Class types[] = new Class[] { String.class, String.class, String.class, String.class };

	Object data[][];
	
	int numberOfAccounts;
    
    public MyTableModel(int numberOfAccounts) {
    	
    	data = new Object[numberOfAccounts][titles.length];
    	
    	this.numberOfAccounts = numberOfAccounts;
    	for(int x = 0; x < this.numberOfAccounts; x++) {
    		for(int y = 0; y < this.titles.length; y++) {
    			data[x][y] = new String[][] { { null, null, null, null } };
    		}
    	}
    }
    
    

    public int getColumnCount() {
      
    	return titles.length;
    }

    public int getRowCount() {
      
    	return data.length;
    }

    public String getColumnName(int col) {
      
    	return titles[col];
    }

    public Object getValueAt(int row, int col) {
      
    	return data[row][col];
    }

    public Class getColumnClass(int c) {
      
    	return types[c];
    }

    public void setValueAt(Object value, int row, int col) {
      
      data[row][col] = value;
      fireTableDataChanged();
      //fireTableCellUpdated(row, col);

    }

    public void reassign(int numberOfAccounts) {
    	data = new Object[numberOfAccounts][titles.length];
    	
    	int updatedNumberOfAccounts = numberOfAccounts;
    	
    	for(int x = 0; x < updatedNumberOfAccounts; x++) {
    		for(int y = 0; y < this.titles.length; y++) {
    			data[x][y] = new String[][] { { null, null, null, null } };
    		}
    	}
    }
}